﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace UI
{
    using Model;
    using BLL;
    using System.Web.Script.Serialization;

    /// <summary>
    /// WebStudent 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    [System.Web.Script.Services.ScriptService]
    public class WebStudent : System.Web.Services.WebService
    {
        JavaScriptSerializer jss = new JavaScriptSerializer();
        BLLClazz BLLClazz = new BLLClazz();
        BLLStudent BLLStudent = new BLLStudent();
        BLLView_Stu_Class BLLView_Stu_Class = new BLLView_Stu_Class();
        /// <summary>
        /// 查询所有班级
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public List<Clazz> SelectClazz()
        {
            return BLLClazz.SelectAll();
        }
        /// <summary>
        /// 添加学生
        /// </summary>
        /// <param name="stu"></param>
        /// <returns></returns>
        [WebMethod]
        public int InsertStudent(Student stu)
        {
            stu.Readed = true;
            return BLLStudent.Insert(stu);
        }
        /// <summary>
        /// 查询所有学生信息(视图)
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public void Proc_SelectPage(int page, int limit)
        {
            LayUITableData<View_Stu_Class> data = new LayUITableData<View_Stu_Class>();
            data.data = BLLView_Stu_Class.Proc_SelectPage(limit, page);
            data.count = BLLView_Stu_Class.Proc_SelectPageCount();
            HttpContext.Current.Response.ContentType = "text/plain";
            HttpContext.Current.Response.Write(jss.Serialize(data));
        }
        /// <summary>
        /// 条件查询学生信息(视图)
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public void Proc_SelectPageWhere(int page, int limit, string name, string sex, string cid, string sdate, string edate)
        {
            View_Stu_Class stu = new View_Stu_Class()
            {
                Name = name,
                CID = string.IsNullOrEmpty(cid) ? (int?)null : Convert.ToInt32(cid),
                Sex = sex
            };
            LayUITableData<View_Stu_Class> data = new LayUITableData<View_Stu_Class>();
            data.data = BLLView_Stu_Class.Proc_SelectPageWhere(limit, page, stu, sdate, edate);
            data.count = BLLView_Stu_Class.Proc_SelectPageCountWhere(stu, sdate, edate);
            HttpContext.Current.Response.ContentType = "text/plain";
            HttpContext.Current.Response.Write(jss.Serialize(data));
        }
        /// <summary>
        /// 根据ID查询学生信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [WebMethod]
        public Student SelectByID(string id)
        {
            return BLLStudent.SelectByID(id);
        }
        /// <summary>
        /// 修改学生信息
        /// </summary>
        /// <param name="stu"></param>
        /// <returns></returns>
        [WebMethod]
        public int Update(Student stu)
        {
            return BLLStudent.Update(stu);
        }

        /// <summary>
        /// 根据ID删除学生信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [WebMethod]
        public int Delete(string id)
        {
            return BLLStudent.Delete(id);
        }
    }
}
